//package com.zj.weather.bgviews;
//
//import android.content.Context;
//import android.graphics.Canvas;
//import android.graphics.Color;
//import android.graphics.Paint;
//import android.graphics.Paint.Style;
//import android.graphics.Rect;
//import android.graphics.RectF;
//import android.graphics.drawable.RotateDrawable;
//
//
//import java.util.ArrayList;
//
//import com.zj.weather.R;
//import com.zj.weather.base.BaseWeatherBgView;
//import com.zj.weather.utils.DisplayUtils;
//import com.zj.weather.utils.StaticValue;
//
//import static com.zj.weather.utils.RandomUtils.getDownRandFloat;
//import static com.zj.weather.utils.RandomUtils.getRandom;
//
//public class WindDrawer extends BaseWeatherBgView {
//
//    public WindDrawer(Context context, int key) {
//        super(context, key);
//        paint.setStyle(Style.STROKE);
//    }
//
//    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//    private static final int count = 50;
//    private static final int fog_count = 2;
//    private ArrayList<ArcHolder> holders = new ArrayList<>();
//    private ArrayList<LeafHolder> leaf_holders = new ArrayList<>();
//    private RotateDrawable leaf;
//
//    @Override
//    public void setSize(int width, int height) {
//        super.setSize(width, height);
//        if (this.holders.size() == 0) {
//            float[] f = getCurAlpha();
//            for (int i = 0; i < count; i++) {
//                float radiusWidth = width * getRandom(1.75f, 4.5f);
//                float radiusHeight = radiusWidth * getRandom(0.78f, 1.16f);//getRandom(width * 0.02f,  width * 1.6f);
//                float strokeWidth = dp2px(getDownRandFloat(0.52f, 1.04f));
//                float sizeDegree = getDownRandFloat(8f, 15f);
//                float alpha = getRandom(f[0], f[1]);
//                this.holders.add(new ArcHolder(-width, radiusWidth, radiusHeight, strokeWidth, sizeDegree, alpha));
//            }
//            for (int i = 0; i < fog_count; i++) {
//                float x = width * getRandom(1.02f, 1.15f);
//                float defaultAlpha = getRandom(f[0], f[1]);
//                leaf_holders.add(new LeafHolder(x, height, defaultAlpha));
//            }
//        }
//    }
//
//    @Override
//    protected void initValues(Context context) {
////        fog = new GradientDrawable(GradientDrawable.Orientation.BL_TR, new int[]{0x03efefef, 0x03ffffff, 0x03e6e6e6, 0x01ffffff, 0x00ffffff});
////        fog.setShape(GradientDrawable.OVAL);
////        fog.setGradientType(GradientDrawable.RADIAL_GRADIENT);
//        leaf = (RotateDrawable) context.getResources().getDrawable(R.drawable.rotate);
//    }
//
//    @Override
//    public void drawWeather(Canvas canvas, float alpha) {
//        for (ArcHolder holder : this.holders) {
//            holder.updateAndDraw(canvas, paint, alpha);
//        }
//        for (LeafHolder holder : leaf_holders) {
//            holder.drawLeaf(canvas, leaf);
//        }
//    }
//
//    public class LeafHolder {
//        float cx, cy, height, from, end, size;
//        private float curOffset, defaultAlpha;
//        private float stepDegree;
//        private Rect rect = new Rect();
//        private float curDegree;
//        private float toDegree;
//
//        LeafHolder(float cx, float h, float defaultAlpha) {
//            this.cx = cx;
//            this.height = h;
//            this.from = -0.002f;
//            this.end = 1.002f;
//            this.defaultAlpha = defaultAlpha;
//            updateDegree();
//        }
//
//        void drawLeaf(Canvas canvas, RotateDrawable drawable) {
//            curOffset += stepDegree;
//            curDegree += stepDegree;
//            float randY = 0.0f;
//            if (curOffset > end) {
//                curOffset = from;
//                updateDegree();
//                randY += getRandom(-0.2f, 0.2f);
//            }
//            rect.left = (int) (cx - cx * curOffset - size / 2f);
//            rect.right = (int) (cx - cx * curOffset + size / 2f);
//            rect.top = (int) (cy - cy * -curOffset - size / 2f) + (int) (randY * cy);
//            rect.bottom = (int) (cy - cy * -curOffset + size / 2f) + (int) (randY * cy);
//            drawable.setBounds(rect);
//            drawable.setAlpha((int) (255f * defaultAlpha));
//            toDegree = curDegree * 10000f;
//            drawable.setLevel((int) toDegree);
//            drawable.draw(canvas);
//        }
//
//        private void updateDegree() {
//            this.cy = height * getRandom(0.1f, 0.5f);
//            this.curDegree = getRandom(0.1f, 1.0f) * 335f;
//            this.stepDegree = getRandom(0.007f, 0.009f);
//            this.size = DisplayUtils.dip2px(context, 33) * getRandom(0.6f, 0.9f);
//        }
//    }
//
//    public class ArcHolder {
//        private float cx, cy, width, radiusWidth, radiusHeight, strokeWidth, fromDegree, endDegree, sizeDegree;
//        private final float alpha;
//        private float curDegree;
//        private final float stepDegree;
//        private RectF rectF = new RectF();
//
//        ArcHolder(float width, float radiusWidth, float radiusHeight, float strokeWidth, float sizeDegree, float alpha) {
//            super();
//            this.width = width;
//            this.radiusWidth = radiusWidth;
//            this.radiusHeight = radiusHeight;
//            this.strokeWidth = strokeWidth;
//            this.fromDegree = 30f;
//            this.endDegree = 99f;
//            this.sizeDegree = sizeDegree;
//            this.alpha = alpha * 0.65f;
//            this.curDegree = getRandom(fromDegree, endDegree);
//            this.stepDegree = getRandom(0.8f, 1.1f);
//            updateParams();
//        }
//
//        void updateAndDraw(Canvas canvas, Paint paint, float al) {
//            paint.setColor(Color.argb(((int) (alpha * al * 255f)), 0xff, 0xff, 0xff));
//            paint.setStrokeWidth(strokeWidth);
//            curDegree += stepDegree * getRandom(0.3f, 0.5f);
//            if (curDegree > (endDegree + sizeDegree)) {
//                curDegree = fromDegree - sizeDegree;
//                updateParams();
//            }
//            float startAngle = curDegree;
//            float sweepAngle = sizeDegree;
//            rectF.left = cx - radiusWidth;
//            rectF.top = cy - radiusHeight;
//            rectF.right = cx + radiusWidth;
//            rectF.bottom = cy + radiusHeight;
//            canvas.drawArc(rectF, startAngle, sweepAngle, false, paint);
//        }
//
//        private void updateParams() {
//            cx = width * 0.5f;
//            cy = width * getRandom(0.65f, 1.15f);
//        }
//    }
//
//    private static float[] getCurAlpha() {
//        float[] alpha = new float[2];
//        if (StaticValue.isDay()) {
//            alpha[0] = 0.55f;
//            alpha[1] = 0.78f;
//        } else {
//            alpha[0] = 0.25f;
//            alpha[1] = 0.32f;
//        }
//        return alpha;
//    }
//}
